package com.dlwx.parttimetalent.views;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.dlwx.parttimetalent.R;
import com.dlwx.parttimetalent.inter.DialogInter;
import com.dlwx.parttimetalent.inter.GetAgeInter;
import com.dlwx.parttimetalent.utils.ToastUtils;
import com.flyco.dialog.widget.base.BaseDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/21.
 */

public class WorkExperienceDialog extends BaseDialog {

    @BindView(R.id.tv_start)
    TextView tvStart;
    @BindView(R.id.tv_end)
    TextView tvEnd;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;
    @BindView(R.id.et_content)
    EditText etContent;
    private Context context;
    private DialogInter inter;
    private String startStr, endStr, unit;

    public WorkExperienceDialog(Context context, DialogInter inter) {
        super(context);
        this.context = context;
        this.inter = inter;

    }

    @Override
    public View onCreateView() {
        widthScale(0.9f);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_wrok_experience, null);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void setUiBeforShow() {

    }


    @OnClick({R.id.tv_start, R.id.tv_end, R.id.tv_cancel, R.id.tv_confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_start:
                AgeDialog ageDialog1 = new AgeDialog(context, new GetAgeInter() {
                    @Override
                    public void getAge(int year, int month, int day, String start) {
                        startStr = year + "-" + month+"-"+day;
                        tvStart.setText(startStr);
                    }
                },true);
                ageDialog1.show();
                break;
            case R.id.tv_end:
                AgeDialog ageDialog2 = new AgeDialog(context, new GetAgeInter() {
                    @Override
                    public void getAge(int year, int month, int day, String start) {
                        endStr = year + "-" + month+"-"+day;
                        tvEnd.setText(endStr);
                    }
                },true);
                ageDialog2.show();
                break;
            case R.id.tv_cancel:
                this.dismiss();
                break;
            case R.id.tv_confirm:
                unit=etContent.getText().toString();
                if(TextUtils.isEmpty(startStr)){
                    ToastUtils.toastForShort(context,"开始时间不能为空");return;
                }
                if(TextUtils.isEmpty(endStr)){
                    ToastUtils.toastForShort(context,"结束时间不能为空");return;
                }
                if(TextUtils.isEmpty(unit)){
                    ToastUtils.toastForShort(context,"工作单位不能为空");return;
                }
                inter.getWorkInfo(startStr, endStr, unit);
                this.dismiss();
                break;
        }
    }
}
